package com.briup.smartcity.web.controller;

import com.briup.smartcity.aop.Logging;
import com.briup.smartcity.bean.Category;
import com.briup.smartcity.service.ICategoryService;
import com.briup.smartcity.utils.Result;
import com.briup.smartcity.utils.ResultUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(tags="咨询栏目模块")
@RestController
@RequestMapping("/auth/category")
public class CategoryController {
    @Autowired
    private ICategoryService service;

    @ApiOperation("根据id删除栏目")
    @DeleteMapping("/deleteById")
    @Logging()
    public Result deleteCategoryById(Integer id){
        service.deleteById(id);

        return ResultUtil.success();
    }

    @ApiOperation("更新栏目信息")
    @PutMapping ("/update")
    @Logging()
    public Result updateCategory(Category category){

        service.updateCategory(category);
    return ResultUtil.success();
    }


    @ApiOperation("保存栏目信息")
    @PostMapping("/save")
    @Logging()
    public Result addCategory(Category category){
        service.saveCategory(category);
        return ResultUtil.success();
    }

    @ApiOperation("批量删除栏目")
    @DeleteMapping("/batchDelete")
    @Logging()
    public  Result batchCategory(int[] ids){
        service.batchDelete(ids);
        return ResultUtil.success();
    }

    @ApiOperation("分页查找栏目信息")
    @GetMapping("/page/queryAll")
    public  Result findAllCategory(Integer pageNum,Integer pageSize){
        PageInfo<Category> pageInfo = service.pageQueryAll(pageNum,pageSize);
        return ResultUtil.success(pageInfo);
    }


    @ApiOperation("查询所有栏目信息不分页")
    @GetMapping("/find/all")
    public Result findAllCategory(){
        List<Category> list=service.findAll();
        return ResultUtil.success(list);

    }




}
